using System;

namespace hemsidan.Entities
{
	/// <summary>
	/// Summary description for Links.
	/// </summary>
	public class Links
	{
		public Links()
		{
		}

		public static System.Data.DataTable GetAll()
		{
			string sql = "select * from Links";
			System.Data.DataSet ds = DataAccess.DB.getInstance().ExecuteDataSet(sql);
			return ds.Tables[0];
		}

		public static System.Data.DataTable GetLinksInCategory(string category)
		{
			string sql = "select * from Links where Category='" + category + "'";
			System.Data.DataSet ds = DataAccess.DB.getInstance().ExecuteDataSet(sql);
			return ds.Tables[0];
		}

		public static System.Data.DataTable GetCategories()
		{
			string sql = "Select distinct Category from Links";
			System.Data.DataSet ds = DataAccess.DB.getInstance().ExecuteDataSet(sql);
			return ds.Tables[0];
		}

		public static void ChangeLink(int LinkId, string Name, string Description, string Address, string Category)
		{
			string sql = "update Links set " +
				"Name='" + Name + "', " +
				"Description='" + Description + "', " +
				"Address='" + Address + "', " +
				"Category='" + Category + "' " +
				"where Id=" + LinkId.ToString();
			DataAccess.DB.getInstance().ExecuteNonQuery(sql);
		}

		public static void DeleteLink(int LinkId)
		{
			string sql = "delete from Links where Id=" + LinkId.ToString();
			DataAccess.DB.getInstance().ExecuteNonQuery(sql);
		}

		public static void CreateLink(string Name, string Description, string Address, string Category)
		{
			string sql = "insert into Links (Name, Description, Address, Category) values ('" +
				Name + "', '" +
				Description + "', '" +
				Address + "', '" +
				Category + "')";
			DataAccess.DB.getInstance().ExecuteNonQuery(sql);
		}
	}
}
